#import <Foundation/Foundation.h>
#import "GCDWebsocketServer.h"
#import "GCDWebServerDataResponse.h"

%hook SpringBoard

- (void)applicationDidFinishLaunching:(id)application {
    %orig;
    NSLog(@"this is a tweak");
    GCDWebsocketServer *server = [[GCDWebsocketServer alloc] init];
    [server addWebsocketHandlerForPath:@"/" withProcessBlock:^GCDWebsocketServerHandler * _Nullable(GCDWebsocketServerConnection * _Nonnull conn) {
        return [GCDWebsocketServerHandler handlerWithConn:conn];
    }];
    [server addHandlerForMethod:@"GET" path:@"/" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
        return [GCDWebServerDataResponse responseWithText:@"ok\n"];
    }];
    NSDictionary *options = @{
        GCDWebServerOption_Port: @(8082),
    };
    NSError *error;
    [server startWithOptions:options error:&error];
    if(error){
        NSLog(@"start server failed for: %@", error);
    }
}

%end